package com.focusai.efairy.ui.adapter.msg;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.focusai.efairy.R;
import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.msg.MsgItem;
import com.focusai.efairy.network.Image.ImageLoaderFactory;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by Luogw on 2017/8/21.
 */

public class MsgChatRightViewBinder extends ItemViewBinder<MsgItem, MsgChatRightViewBinder.ViewHolder> {

    private Context mContext;
    private String userName;
    private String userAvater;

    public MsgChatRightViewBinder(Context mContext) {
        this.mContext = mContext;
        userName = CacheManager.getUserName();
        userAvater = CacheManager.getUserAvater();
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_msg_right, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull MsgItem item) {
        holder.userName.setText(userName);
        holder.msgContent.setText(item.get_content());
        holder.timeText.setText(item.getmsg_time());
        ImageLoaderFactory.getImageLoader().loadImage(mContext, holder.avater, userAvater,R.drawable.user_default_icon,false);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView avater;
        TextView userName;
        TextView msgContent;
        TextView timeText;
        ViewHolder(View itemView) {
            super(itemView);
            avater = (ImageView) itemView.findViewById(R.id.msg_user_avater);
            userName = (TextView) itemView.findViewById(R.id.chat_msg_name);
            msgContent = (TextView) itemView.findViewById(R.id.chat_msg_content);
            timeText = (TextView) itemView.findViewById(R.id.chatting_msg_item_tv_sendtime);
        }

    }
}
